package com.gis507.test.AisTest3;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.junit.Test;

import java.io.IOException;

/**
 * 1、继承Mapper
 * 2、重写map方法
 * 3、key：AisBean  value：Text
 */
public class AisMapper extends Mapper<LongWritable,Text, Text,AisBean> {

    private Text outK = new Text();
    private AisBean outV = new AisBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1、获取一列
        String line = value.toString();

        //2、按照“，”进行分割
        String[] comment = line.split(line);

        //3、获取数值
        String mmsi = comment[0];
        Double speed = Double.parseDouble(comment[1]);
        Long unixTime = Long.parseLong(comment[2]);
        Double lon_d = Double.parseDouble(comment[3]);
        Double lat_d = Double.parseDouble(comment[4]);

        //4、封装对象
        outK.set(mmsi);

        outV.setSpeed(speed);
        outV.setUnixTime(unixTime);
        outV.setLon_d(lon_d);
        outV.setLat_d(lat_d);

        //5、写出
        context.write(outK,outV);
    }

}
